{include file="Public:header2"/}

<body>
<div class="layui-fluid">
    <div class="layui-card">
        <form method="get"  class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">搜索商品</label>
                    <div class="layui-input-block">
                        <input type="text" name="keyword" style="width: 300px" value="{$Request.get.keyword}" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
               <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="status" style="width:100%">
                            <option value="">--请选择状态--</option>
                            <option value="0" {if condition="$Request.get.status === '0'"}selected{/if}>上架</option>
                            <option value="1" {if condition="$Request.get.status eq 1"}selected{/if}>下架</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </form>

        <div class="layui-card-body">
            <xblock>
                <div style="padding-bottom: 10px;">
                    <a class="layui-btn" href="{:url('/admin/seckill_product_add')}">添加商品</a>
                    <!--<a style="text-decoration:none" title="操作" onClick="status_update('',0)" class="layui-btn layui-btn-normal">批量上架</a>-->
                    <!--<a style="text-decoration:none" title="操作" onClick="status_update('',1)" class="layui-btn layui-btn-normal">批量下架</a>-->
                    <!--<a style="text-decoration:none" title="操作" onClick="status_update('',2)" class="layui-btn layui-btn-danger">批量删除</a>-->
                    <span style="line-height:40px;float:right;">共有数据： {$count}条</span>
                </div>
            </xblock>
            <table class="layui-table" style="text-align:center">
                <thead>
                <tr>
                    <th style="width: 20px"><input type="checkbox"  class="all-check" /></th>
                    <th class="ccc">ID</th>
                    <th class="ccc">一级分类</th>
                    <th class="ccc">二级分类</th>
                    <th class="ccc">商品名称</th>
                    <th class="ccc">商品图片</th>
                    <th class="ccc">商品价格</th>
                    <th class="ccc">销售数量</th>
                    <th class="ccc">商品排序</th>
                    <th class="ccc">添加时间</th>
                    <th class="ccc">状态</th>
                    <th class="ccc">操作</th>
                </tr>
                </thead>
                <tbody>
                    {volist name="list" id="vo"}
                        <tr>
                            <td><input type="checkbox"  class="shell-check Keys" Key="{$vo['id']}"/></td>
                            <td>{$vo.id}</td>
                            <td>
                                <p><span>{$vo['cate_name1']}</span></p>
                            </td>
                            <td>
                                <p><span>{$vo['cate_name2']}</span></p>
                            </td>
                            </td>
                            <td>{$vo['title']}</td>
                            <td><img src="{:imageUrl($vo['image'])}" style="width:60px;height:60px;"></td>
                            <td style="text-align:left;">
                                <div style="display: flex"><p style="width: 60px;display: inline">售价</p> ：{$vo['price']}</div>
                                <div style="display: flex"><p style="width: 60px;display: inline">秒杀价</p> ：{$vo['seckill_price']}</div>
                                <div style="display: flex;color: #f4433691"><p style="width: 60px;display: inline">运费</p> ：{$vo['freight']}</div>
                            </td>
                            <td>{$vo['sale_num']}</td>
                            <td>{$vo['sort']}</td>
                            <td>{$vo['addtime']|date="Y-m-d H:i"}</td>
                            <td>
                                {if condition="$vo['status'] eq 0"}
                                <button class="layui-btn layui-btn-normal layui-btn-radius layui-btn-sm">上架</button>
                                {else /}
                                <button class="layui-btn layui-btn-warm layui-btn-radius layui-btn-sm">下架</button>
                                {/if}
                            </td>
                            <td>
                                <a style="text-decoration:none" title="编辑" href="{:url('/admin/seckill_product_edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-radius layui-btn-normal layui-btn-xs">
                                    <i class="layui-icon layui-icon-edit"></i>编辑
                                </a>
                                {if condition="$vo['status'] eq 0"}
                                <a style="text-decoration:none" title="操作" onClick="status_update({$vo.id},1)" class="layui-btn layui-btn-danger layui-btn-xs">下架</a>
                                {else /}
                                <a style="text-decoration:none" title="操作" onClick="status_update({$vo.id},0)" class="layui-btn layui-btn-danger layui-btn-xs">上架</a>
                                {/if}
                                <a style="text-decoration:none" title="操作" onClick="status_update({$vo.id},2)" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
                            </td>
                        </tr>
                    {/volist}
                
                        {if condition="empty($list)"}
                            <tr><td colspan='10' style="text-align:center;">暂时没有数据！</td></tr>
                        {/if}
                </tbody>
            </table>
            <div class="layui-box layui-laypage layui-laypage-default">
                {$page|raw}
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
<script type="text/javascript">
    layui.use(['table'], function(){
        var $ = layui.$;
        var form = layui.form;

        $(".all-check").click(function () {
            $(".shell-check").prop("checked", this.checked);
        });
        $(".shell-check").click(function () {
            var option = $(".shell-check");
            option.each(function (i) {
                if (!this.checked) {
                    $(".all-check").prop("checked", false);
                    return false;
                } else {
                    $(".all-check").prop("checked", true);
                }
            });
        });
    });


    //修改状态
    function status_update(id,stu){
        layer.confirm('确认要执行当前操作吗？',function(){
            var url = "{:url('/admin/seckill_product_del')}";
            var load=layer.load(2);
            var $ = layui.$;

            var ids = []
            if (id == '') {
                $.each($('.Keys'), function (key, value) {
                    if ($(value).prop("checked")) {
                        ids.push(parseInt($(value).attr('Key')))
                    }
                })
            } else {
                ids.push(id)
            }
            if(ids.length <= 0){
                layer.msg('请选择数据',{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
                return false;
            }

            $.post(url,{"id":ids,status:stu},function(data){
                if(data.status == 1){
                    layer.msg(data.msg,{icon:1,time:1000},function(){
                        location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                        layer.close(load);
                    });
                }
            })
        });
    }

</script>
</body>
</html>


